<template>
  <div>
    <el-row
      v-if="!isMultiple"
      type="flex"
      class="attachment"
      :style="'margin-left:'+ fileMarginCss"
    >
      <el-col :span="7">
        <span
          class="icon"
          :title="fileObj.fileName"
        >{{ fileObj.fileName }}</span>
        <a
          class="color-primary w60"
          @click="downloadFile(fileObj.fileId)"
        >下载</a>
        <a
          v-show="showClose"
          class="color-danger w60"
          @click="removeFile"
        >删除</a>
      </el-col>
    </el-row>
    <!-- 多个附件 -->
    <div v-else>
      <el-row
        v-for="(item, index) in fileObjList"
        :key="item.fileId"
        type="flex"
        class="attachment"
        :style="'margin-left:' + fileMarginCss"
      >
        <el-col :span="7">
          <span
            class="icon"
            :title="item.fileName"
          >{{ item.fileName }}</span>
          <a
            class="color-primary w60"
            @click="$commonUtil.downloadFileCommonTwo(item.fileId)"
          >下载</a>
          <a
            v-show="showClose"
            class="color-danger w60"
            @click="removeFileItem(index, item.fileId)"
          >删除</a>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>

export default {
	name: 'FileList',
	props: {
		showClose: {
			default: true,
			type: Boolean,
		},
		fileObj: {
			default: () => {},
			type: Object,
		},
		// 多个附件存在时
		fileObjList: {
			default: () => [],
			type: Array,
		},
		// 是否上传多文件
		isMultiple: {
			type: Boolean,
			default: false,
		},
		fileMarginCss: {
			type: String,
			default: '0px',
		},
	},
	data() {
		return {
		};
	},
	methods: {
		removeFile() {
			this.$emit('removeFile');
		},
		// 多个附件时 删除附件
		removeFileItem(index, fileId) {
			this.$emit('removeFileItem', index, fileId);
		},
	},
};
</script>
<style scoped>
.attachment {
    flex-wrap: wrap;
    box-sizing: border-box;
}
.attachment .el-col {
    font-size: 14px;
    width: 260px;
    height: 36px;
    line-height: 36px;
    border-radius: 5px;
    box-sizing: border-box;
    display: flex;
    margin-right: 10px;
    margin-bottom: 5px;
    justify-content: space-around;
    background: #fff;
    box-shadow: 0px 1px 8px 0px rgba(0, 0, 0, 0.05);
}
.attachment .icon {
    position: relative;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    width: 180px;
    margin-left: 25px;
}

.attachment .el-col::after {
    content: ' ';
    width: 16px;
    height: 18px;
    display: inline-block;
    margin-right: 5px;
    background: url(./attachment.png);
    background-size: contain;
    position: absolute;
    top: 10px;
    left: 10px;
}
.w60{display: inline-block; width: 60px;}
.color-danger{color: red;}
</style>
